import { h } from 'vue'
import request from '@/utils/request'
const url = 'http://10.2.1.130:8130/steel_pmo/behave'
export default class Behave {
    constructor() {

    }
    pageObj(data: any) {
        return request.post({
            url: `${url}/pageObj`,

            data
        })
    }
    count4Page(data: any) {
        return request.post({
            url: `${url}/count4Page`,

            data
        })
    }
    createObj(data: any): any {
        return request.post({
            url: `${url}/createObj`,

            data: this.format(data)
        })
    }
    getObjById(data: any): any {
        return request.post({
            url: `${url}/getObjById`,

            data
        })
    }

    updateObj(data: any): any {
        return request.post({
            url: `${url}/updateObj`,

            data: this.format(data)
        })
    }

    listObj(data: any): any {
        return request.post({
            url: `${url}/listObj`,

            data
        })
    }

    deleteObj(data: any): any {
        const ID = this.getKey(data)
        return request.post({
            url: `${url}/deleteObj`,

            data: { ID }
        })
    }

    deleteObjs(data: any): any {
        return request.post({
            url: `${url}/deleteObjs`,

            data
        })
    }

    getDesc(obj: any): any {
        return obj.Name
    }
    getKey(obj: any): any {
        return "" + obj.Token
    }
    getDescField(): any {
        return 'Name'
    }
    getKeyField(obj: any): any {
        return ["Token"]
    }
    format(obj: any): any {
        if (null !== obj.PlanEndUtc && undefined !== obj.PlanEndUtc) {
            obj.PlanEndUtc = parseFloat("" + obj.PlanEndUtc)
        }
        if (null !== obj.RealEndUtc && undefined !== obj.RealEndUtc) {
            obj.RealEndUtc = parseFloat("" + obj.RealEndUtc)
        }
        if (null !== obj.StartUtc && undefined !== obj.StartUtc) {
            obj.StartUtc = parseFloat("" + obj.StartUtc)
        }
        if (null !== obj.Status && undefined !== obj.Status) {
            obj.Status = parseFloat("" + obj.Status)
        }
        return obj
    }
    format4Select(obj: any): any {
        return obj
    }
    // 字段的名称
    fields = [
        {
            title: '项目',
            dataIndex: 'ProjectDesp',
            key: 'project0.name',
            query: true,
            sorter: true
        },
        {
            title: '名称',
            dataIndex: 'Name',
            key: 'behave.name',
            query: true,
            sorter: true
        },
        {
            title: '开始时间',
            dataIndex: 'StartUtc',
            key: 'behave.start_utc',
            query: false,
            sorter: true,
            width: 112
        },
        {
            title: '计划结束时间',
            dataIndex: 'PlanEndUtc',
            key: 'behave.plan_end_utc',
            query: false,
            sorter: true,
            width: 140
        },
        {
            title: '实际结束时间',
            dataIndex: 'RealEndUtc',
            key: 'behave.real_end_utc',
            query: false,
            sorter: true,
            width: 140
        },
        {
            title: '状态',
            dataIndex: 'Status',
            key: 'behave.status',
            render: (t: any, itemData: any, item: any) => {
                switch (itemData) {
                    case 0: return h('span', {}, '未开始')
                    case 1: return h('span', {}, '进行中')
                    case 2: return h('span', {}, '已完成')
                    case 3: return h('span', {}, '延误')
                }
            },
            query: false,
            sorter: true,
            width: 84
        }
    ]
}
